Skip to content

feat(provenance): resolve source git SHA via a validated multi-channel chain - #491

Open
arekay-nv wants to merge 3 commits into
mainfrom
feat/git-sha-provenance
Open

arekay-nv wants to merge 3 commits into
mainfrom
feat/git-sha-provenance

Conversation

@arekay-nv

@arekay-nv arekay-nv commented Sep 1, 2026 •

Copy link
Copy Markdown
Collaborator

What & why

Records the endpoints source commit in every run's report, so a
result_summary.json / report.txt is self-describing about which code
produced it.

resolve_git_sha() walks a channel chain (first hit wins), validating every
value against a hex-SHA grammar ([0-9a-fA-F]{7,64}, optional -dirty):

Order Channel Populated by Used in
1 git live git rev-parse of the package's own source checkout (src/ layout + toplevel guard, not cwd) dev checkouts, bind-mounted checkouts
2 env ENDPOINTS_GIT_SHA (docker --build-arg GIT_SHA → ENV); ignored inside a git checkout container images, installed packages
3 none — nothing resolvable

A checkout reports live git or nothing. If <root>/.git exists but git can't
read it (git missing, a timeout, dubious ownership, a .git pointing outside a
bind mount), the report says unknown (source: none) and a warning is logged,
rather than recording an image's ENDPOINTS_GIT_SHA, which describes other
code.

The SHA gains -dirty when tracked files in the code that runs differ from
HEAD: src/inference_endpoint, pyproject.toml, uv.lock, and the VBench
scorer subproject under examples/. Untracked files and LFS data elsewhere are
ignored. The probe is
git -c core.checkStat=minimal status --porcelain --untracked-files=no -- <paths>
under GIT_OPTIONAL_LOCKS=0: copied/rsynced checkouts and Docker Desktop bind
mounts (synthetic inode numbers) aren't re-hashed, so they aren't falsely dirty,
and the caller's index is never written. A probe that fails or times out (5s)
reports -dirty and logs why.

Provenance is resolved once per process, at the start of setup_benchmark
(and logged), so every report the process writes — main run and audit phases —
records the same SHA, sampled before the run rather than after it.

The report always prints Git SHA: <sha> (source: <channel>), and
git_sha_source is recorded in result_summary.json.

Changes

  • utils/version.py: validated git → env → none resolver; checkout gate;
    scoped checkStat=minimal dirty probe that warns on failure; bytes-safe
    rev-parse; git repo-location env scrub (GIT_DIR/GIT_WORK_TREE/
    GIT_INDEX_FILE/…) so a stray GIT_DIR can't slip a foreign SHA past the
    toplevel guard; per-process memo.
  • commands/benchmark/execute.py: setup_benchmark pins and logs
    provenance before any work runs.
  • metrics/report.py: new required git_sha_source field; unconditional
    Git SHA: display line.
  • scripts/push_docker_image.sh (feat :Testing workflow to push images #405 publish path): forwards
    --build-arg GIT_SHA=<short sha>[-dirty] — the same --short=7 SHA as the
    image tag, with the runtime's dirty scope — so published GHCR images report
    their commit at runtime instead of source: none.
  • scripts/Dockerfile.dev: ARG GIT_SHA → ENV ENDPOINTS_GIT_SHA, last so
    the per-commit value doesn't bust cached layers; documented build command
    carries -dirty.
  • docs (docs/metrics/*, docs/utils/DESIGN.md) + tests.

Testing

  • test_version.py: hermetic tmp repos (no ambient git config or GIT_*);
    real-git tests for dirty scope, copied checkouts, filtered (LFS-style) files
    with stat-only changes, unreadable checkouts (gitfile outside a mount,
    dangling .git symlink) and index immutability; fake-subprocess.run tests
    that decode exactly when the real call would; a test keeping the image-build
    pathspec equal to the runtime's. Mutation-checked: reverting any of the
    behaviors above fails at least one test.
  • Docker Desktop with inference-endpoint-dev (no git-lfs) and the LFS parquet
    smudged in a clean bind-mounted clone: (sha, "git"), no false -dirty; a
    bind-mounted worktree whose .git points outside the mount: (None, "none")
    plus the warning, with the image's ENDPOINTS_GIT_SHA set.
  • End-to-end CLI against the echo server (offline, and from-config with an
    audit: output-caching block): the setup log line precedes the run;
    report.txt and result_summary.json carry the same SHA across the main and
    audit-phase reports; git runs only at setup (2 invocations per process).
  • Full suite: no new failures vs main (remaining local failures are the
    macOS-only socket-path / sched_*affinity / /proc ones, identical on
    main).

Follow-ups (not in this PR)

  • A baked build-info channel for installed wheels, landing together with
    the CI step that generates it (and removes it after uv build).

Notes

  • Report.git_sha_source is a new required struct field; nothing decodes
    Report back from JSON, so there is no wire/back-compat break.
  • Known limitation: code mounted into the image without its .git (a
    tarball, or src/ alone) can't be told apart from the image's own copy and
    reports the image's ENDPOINTS_GIT_SHA. Mount the whole checkout.

🤖 Generated with Claude Code

@github-actions
github-actions Bot requested a review from nvzhihanj September 1, 2026 02:36
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@github-actions github-actions Bot added the size/normal PR Review Policy: <=500 non-test lines & <=20 files label Sep 1, 2026
Comment thread tests/unit/test_version.py Fixed
Comment thread tests/unit/test_version.py Fixed
…l chain

Record the endpoints source commit in every run's report. resolve_git_sha
falls through live git of the package's own source checkout (dev,
bind-mounted sources) -> baked build-info (wheels) -> ENDPOINTS_GIT_SHA
(containers) -> none, validating each channel against a hex-SHA grammar
([0-9a-fA-F]{7,64}, optional -dirty) and appending -dirty for uncommitted
tracked changes. The report now always prints
`Git SHA: <sha> (source: <channel>)` and records git_sha_source in
result_summary.json.

- utils/version.py: _valid_sha grammar on all channels; git is consulted only
  from the <root>/src/inference_endpoint/ layout, behind a toplevel guard;
  git-location env family scrub (GIT_DIR/GIT_WORK_TREE/GIT_INDEX_FILE/...);
  fail-to-dirty `git status --porcelain --untracked-files=no` probe under
  GIT_OPTIONAL_LOCKS=0 (copied/rsynced checkouts aren't falsely dirty, the
  index is never written); corrupt-bake tolerance; resolved once per report
  (no lru_cache)
- metrics/report.py: new required git_sha_source field; unconditional Git SHA
  display line
- scripts/write_build_info.py: build-time generator (toplevel + hex validated,
  own env scrub, same dirty probe, atomic write); .dockerignore keeps a stray
  local bake out of images; uv_build packs it into wheels
- scripts/Dockerfile.dev: ARG GIT_SHA -> ENV ENDPOINTS_GIT_SHA, declared last
  so the per-commit value doesn't bust cached layers
- scripts/push_docker_image.sh: forward GIT_SHA (+ -dirty) so published images
  report their commit at runtime
- docs/metrics/*, docs/utils/DESIGN.md: document the field + fallback chain
- tests: version, generator, report serialization

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
arekay-nv and others added 2 commits October 26, 2026 09:58
… setup

Address review findings on the git SHA provenance chain:

- Drop the baked _build_info.py channel (generator, its tests, .dockerignore,
  .gitignore entry); it returns together with the CI step that produces it.
  The chain is now git -> env -> none, and ENDPOINTS_GIT_SHA is ignored when
  the package sits in a git checkout that git can't read, so a bind-mounted
  checkout never reports an image's SHA for other code.
- Scope the dirty probe to the code that runs and its pins
  (src/inference_endpoint, pyproject.toml, uv.lock, the VBench scorer
  subproject) and run it with core.checkStat=minimal, so LFS data and
  synthetic inode numbers (Docker Desktop bind mounts) no longer read as
  -dirty. A failed probe still reports -dirty and now logs why; the probe
  budget is 5s.
- Resolve provenance once per process: setup_benchmark calls
  get_version_info() first and logs it, so main-run and audit-phase reports
  agree and no git subprocess runs after the benchmark.
- Read rev-parse output as bytes so a non-UTF-8 checkout path can't fail
  report building.
- push_docker_image.sh / Dockerfile.dev: --short=7 for the image tag and
  GIT_SHA, dirty check with the runtime's pathspec.
- Tests: hermetic git helpers, a parametrized resolver table, and real-git
  tests for dirty scope, copied checkouts, filtered files with stat-only
  changes, unreadable checkouts and index immutability, plus a test keeping
  the image-build pathspec in sync with the runtime's.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/normal PR Review Policy: <=500 non-test lines & <=20 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant